package com.example.ktapplication.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.ktapplication.R
import com.example.ktapplication.base.TabViewpagerFragment
import com.example.ktapplication.model.SystemViewModel

class ProjectTabFragment : TabViewpagerFragment() {

    private val viewModel by lazy {
        ViewModelProvider(this)[SystemViewModel::class.java]
    }

    private val pages by lazy {
        mutableMapOf<String, Fragment>()
    }

    override fun onDate(savedInstanceState: Bundle?) {
        viewModel.projectData.observe(this) { data ->
            data.map {
                pages.put(it.name, BlogListFragment(it.id, BlogListFragment.BLOG_REQ_PROJECT))
            }
            setupViewPager(pages.toList())
        }
    }

    override fun onViewBing() {
        super.onViewBing()
        binding.tabLayout.setBackgroundColor(resources.getColor(R.color.color_f2))
    }

    override fun loadData() {
        viewModel.getProject()
    }

}